#!/bin/bash
 
# 获取缓存命中和未命中的次数
cache_hit=$(grep '^cpu ' /proc/stat | awk '{print $4}')
cache_miss=$(grep '^cpu ' /proc/stat | awk '{print $5}')
 
# 计算总的缓存次数
cache_total=$((cache_hit + cache_miss))
 
# 计算缓存命中率
if [ "$cache_total" -ne 0 ]; then
  cache_hit_rate=$(printf "%.2f%%\n" "$(echo "scale=2;$cache_hit/$cache_total*100" | bc)")
  echo "Cache Hit Rate: $cache_hit_rate"
else
  echo "Cache Hit Rate: 0%"
fi
